package core

class LegalIdentifier {

	String idValue
	//String nameVale
	//Country issuingCountry
	DocumentType documentType
	Date validFrom
	Date validTo
	
	static belongsTo = [person:Person, issuingCountry:Country]
	static constraints = {
		validFrom nullable:true, validator: { val, obj, errors ->
			if (val == null) return true
			if (val > new Date() ) 
				return "Invalid validFrom Date ${val} cannot be in the Future"
			if (val < obj.person.birthDate ) 
				errors.rejectValue('validFrom', ' Can not be Valid before the person birth')
		}
		validTo nullable:true, validator: { val, obj -> 
			if (val == null) return true
			if (val <= obj.validFrom) 
				return "Invalid validTo Date ${val} cannot be before validFrom ${obj.validFrom}"
		}
		idValue blank:false, validator: {
			if (it.size() < 5 ) return false
		} 
	}
	
	static mapping = {
		//issuingCountry fetch: 'join'
	}
//	int compareTo(obj) {
//		validFrom.compareTo(obj.validFrom)
//	}
		
}
